package com.kl.drs.service.impl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.kl.drs.bean.bo.CCBLCContBO;
import com.kl.drs.bean.bo.DrsAsynchTaskBO;
import com.kl.drs.bean.bo.DrsLdcomRelationBO;
import com.kl.drs.bean.bo.LaAgentBO;
import com.kl.drs.bean.bo.RelationIdBO;
import com.kl.drs.bean.bo.RelationMappingBO;
import com.kl.drs.bean.bo.TaskInfoBO;
import com.kl.drs.bean.dto.CoreInfoDTO;
import com.kl.drs.bean.dto.PSBCInfoDTO;
import com.kl.drs.common.BusinessKey;
import com.kl.drs.dao.BankButtjointDAO;
import com.kl.drs.dao.DrsAsynchTaskDAO;
import com.kl.drs.dao.TaskInfoDAO;
import com.kl.drs.service.BankButtjointService;
import com.kl.drs.util.ConfigsUtil;
import com.kl.drs.util.CopyFileUtil;
import com.kl.drs.util.DateUtils;
import com.kl.drs.util.DelFileUtil;
import com.kl.drs.util.FileUtil;
import com.kl.drs.util.Log4jUtils;
import com.kl.drs.util.VideoConvertUtil;
import com.kl.drs.util.VideoFileUtils;

@Service("bankButtjointService")
public class BankButtjointServiceImpl implements BankButtjointService{
	@Autowired
	private BankButtjointDAO bankButtjointDAO;
	@Autowired
	private TaskInfoDAO taskInfoDAO;
	@Autowired
	private DrsAsynchTaskDAO drsAsynchTaskDAO;
	
	/*获取工行的ftp视频路径*/
	@Value("${icbc.ftp.video.path}")
	private String ftpVideoPath;
	/*获取本地服务器视频路径*/
	@Value("${video.path}")
	private String videoPath;
	/*获取ffmpeg配置视频路径*/
	@Value("${ffmpeg.link.path}")
	private String ffmpegPath;
	/*工行文件备份*/
	@Value("${icbc.ftp.copy.path}")
	private String copyFile;
	/*邮储服务器bbcp连接地址*/
	@Value("${psbc.link.bbcp.path}")
	private String bbcpPath;
	/*邮储文件备份*/
	@Value("${psbc.link.copy.path}")
	private String psbcCopyPath;
	//保险公司编号
	@Value("${subinsurer.code}")
	private String subInsurerCode;
	//保险公司总代码
	@Value("${insurer.code}")
	private String insurerCode;
	//工行编码
	@Value("${icbc.code}")
	private String icbcBankCode;
	//邮储编码
	@Value("${psbc.code}")
	private String psbcBnakCode;
	

	
	/**
	 * 查询核心数据（建行）
	 */
	@Override
	public List<CCBLCContBO> queryCoreInfoService(String contNo) {
		
		return bankButtjointDAO.queryCoreInfoList(contNo);
	}
	/**
	 * 查询流水号进行查询业务(建行)
	 */
	@Override
	public CCBLCContBO queryContNo(String serialNo) {
		// TODO Auto-generated method stub
		return bankButtjointDAO.queryContNo(serialNo);
	}
	/**
	 * 查询证件关联（证件类型和证件编码）
	 */
	@Override
	public RelationIdBO queryIdTypeRelService(Map<String, String> condMap) {
		
		return this.bankButtjointDAO.queryIdTypeRel(condMap);
	}
	/**
	 * 查询关联机构(机构编码和机构类型)
	 */
	@Override
	public RelationMappingBO queryMappingTypeRelService(Map<String, String> condMap) {
		
		return this.bankButtjointDAO.queryMappingTypeRel(condMap);
	}
	/**
	 * 新增关联证件
	 */
	@Override
	public int addIdTypeRelService(RelationIdBO relationIdBO) {
		// TODO Auto-generated method stub
		return this.bankButtjointDAO.addIdTypeRel(relationIdBO);
	}
	/**
	 * 新增关联编码
	 */
	@Override
	public int addMappingTypeRelService(RelationMappingBO relationMappingBO) {
		
		return this.bankButtjointDAO.addMappingTypeRel(relationMappingBO);
	}
	/**
	 * 中国邮政银行查询核心数据接口
	 */
	@Override
	public List<PSBCInfoDTO> queryPsbcCoreInfoService(String prtNo) {
		// TODO Auto-generated method stub
		return this.bankButtjointDAO.queryCoreInfo(prtNo);
	}
	/**
	 * 根据保单号查询险种和缴费信息(建行)
	 */
	@Override
	public List<CCBLCContBO> queryCoreRisk(String contNo) {
		// TODO Auto-generated method stub
		return bankButtjointDAO.queryCoreRisk(contNo);
	}
	
	/**
	 * 查询机构关联
	 * @param manageCom
	 */
	@Override
	public DrsLdcomRelationBO queryDrsLdcomRel(String manageCom) {
		return bankButtjointDAO.queryDrsLdcomRel(manageCom);
	}
	/**
	 * 查询销售人员信息
	 * @param bankCode
	 * @param bankBranch
	 * @param bankNode
	 */
	@Override
	public LaAgentBO queryAgentName(Map<String, String> conMap) {
		return bankButtjointDAO.queryAgentName(conMap);
	}
	/**
	 * 联查查询关联机构
	 * @param relationCode
	 * @param bankRelationType
	 * @param reRelationType
	 * @return
	 */
	public String queryIdcodeByUnion(String relationCode,String bankRelationType,String reRelationType){
		return bankButtjointDAO.queryIdcodeByUnion(relationCode, bankRelationType, reRelationType);
	}
	
	/**
	 * 条件查询核心新单数据
	 * @param queryMap
	 * @return
	 */
	public CoreInfoDTO queryCoreLCbyBusinessNo(Map<String, String> queryMap){
		return bankButtjointDAO.queryCoreLCbyBusinessNo(queryMap);
	}
	/**
	 * 条件查询核心（撤单、犹退、退保）数据
	 * @param queryMap
	 * @return
	 */
	public CoreInfoDTO queryCoreLBbyBusinessNo(Map<String, String> queryMap){
		return bankButtjointDAO.queryCoreLBbyBusinessNo(queryMap);
	}
	

	/**
	 * 对接工行
	 * @throws Exception 
	 */
	@Override
	public void buttjointICBCService(String bankType) throws Exception {
	    String dateStr = DateUtils.formatDate("yyyyMMdd");
		TaskInfoBO taskInfoBO=new TaskInfoBO();
		RelationMappingBO mappingRel=new RelationMappingBO();
		Map<String,String> videoMap=new HashMap<String,String>();
		List<TaskInfoBO> listFile = new ArrayList<TaskInfoBO>();
		File file = new File(ftpVideoPath) ;
		 if(file.isDirectory()){
		     File f[] = file.listFiles() ;
		     if(f!=null){
		     for(int i = 0 ; i<f.length ; i++){    
		    	if(f[i].getName().endsWith(".avi")){
		    		Log4jUtils.logDebug(f[i].getName());
		    		 String[] icbcButtjoinArr=f[i].getName().split("_");
		    		 String key=icbcButtjoinArr[2];
		    		 videoMap.put(key,f[i].getName());
		    		 Log4jUtils.logDebug("id："+videoMap.get(icbcButtjoinArr[2]));
		    		
		    	 }else if(f[i].getName().endsWith(".txt")){
		    		//getTextFromTxt(f[i]);
		    		listFile.addAll(getTextFromTxt(f[i]));
		    		DelFileUtil.deleteOneFile(ftpVideoPath+f[i].getName());
				    Log4jUtils.logDebug("**************删除文件结束*****************");
		 		    }  
		    	 }
		     }
		     } 
		for (TaskInfoBO taskInfo : listFile) {
			Log4jUtils.logDebug("对象是:"+taskInfo.toString());
			TaskInfoBO task = this.taskInfoDAO.queryTaskInfo(taskInfo);
			String businessNo=taskInfo.getBusinessNo();
			String videoName=videoMap.get(businessNo);
			String videoFilePath=ftpVideoPath+File.separator+videoName;
			if(task==null){
				Log4jUtils.logDebug(videoMap.get(taskInfo.getBusinessNo()));
				Log4jUtils.logDebug("能双录的是对应的影像批次号是:"+taskInfo.getBusinessNo());
				File target=null;
				target=new File(videoFilePath);
				if(target.exists()){
					String videoType=videoName.substring(videoName.length()-3,videoName.length());
					if(videoType.equalsIgnoreCase("avi")){
					/*视频的转换*/
					String videoSavePath=videoPath+dateStr+File.separator;
					File videoSaveFile=new File(videoSavePath);
					if(!videoSaveFile.exists()){
						videoSaveFile.mkdirs();
					}
					Log4jUtils.logDebug("视频转换路径:"+videoSavePath+videoName.substring(0,videoName.length()-4));
					VideoConvertUtil.processFLV(videoFilePath,videoSavePath+videoName.substring(0,videoName.length()-4),ffmpegPath);
					String vName=videoName.substring(0,videoName.length()-4)+".flv";
					taskInfo.setVideoName(vName);
					/*视频类型*/
					String prefix=vName.substring(vName.length()-3, vName.length());
					taskInfo.setVideoType(prefix);
					taskInfo.setVUrl(dateStr);
					/*获取视频文件的长度*/
					File videoFile=new File(videoSavePath+vName);
					Log4jUtils.logDebug("开始获取视频文件，对应的文件名："+vName);
					taskInfo.setFileLength(videoFile.length());
					Log4jUtils.logDebug("获取到的视频文件长度是："+taskInfo.getFileLength());
					/*获取视频文件的时长*/
					taskInfo.setFileTime(VideoFileUtils.getVideoFileTime(videoSavePath+vName));
					
					Log4jUtils.logDebug("组成后的对象是:"+taskInfo.toString());
					}else{
						taskInfo.setVideoName(target.getName());
						taskInfo.setVideoType(videoType);
						/*获取视频文件的长度*/
						taskInfo.setFileLength(target.length());
						/*获取视频文件的时长*/
						taskInfo.setFileTime(VideoFileUtils.getVideoFileTime(videoFilePath));
					}
					int createFlag=this.taskInfoDAO.addTaskInfo(taskInfo);
					if(createFlag<1){
						Log4jUtils.logDebug("上传失败！！！");
					}else{
						DrsAsynchTaskBO drsAsynchTask = new DrsAsynchTaskBO();
						drsAsynchTask.setBusinessNo(taskInfo.getBusinessNo());
						drsAsynchTask.setBusinessSerialNo(taskInfo.getBusinessSerialNo());
						drsAsynchTask.setTaskType(BusinessKey.ASYNCH_TYPE_UB);
						drsAsynchTask.setStatus(BusinessKey.ASYNC_TASK_STATUS_WAIT);
						drsAsynchTaskDAO.addDrsAsynchTask(drsAsynchTask);
						
					}
					CopyFileUtil.copyOneFile(videoFilePath,copyFile+dateStr+File.separator+videoName);
					Log4jUtils.logDebug("双录成功，对应的业务识别号:"+taskInfo.getBusinessNo());
					DelFileUtil.deleteOneFile(videoFilePath);
				    Log4jUtils.logDebug("**************删除文件结束*****************");

				}else{
					Log4jUtils.logDebug("视频文件不存在，对应的批次号是："+taskInfo.getBusinessNo());
				}
				
			}else{
				Log4jUtils.logDebug("信息已经双录，不能再次双录");
				Log4jUtils.logDebug("不能双录对应的业务识别号:"+taskInfo.getBusinessNo());
			}
		}
			
		 }
	public List getTextFromTxt(File fileTxt) throws Exception {   
		FileReader fr = new FileReader(fileTxt);   
	    BufferedReader br = new BufferedReader(fr);   
	    StringBuffer buff = new StringBuffer();   
	    String lineBankInfo = null;
	    Map<String, String> condMap=new HashMap<String, String>();
	    List list=new ArrayList();
	    RelationMappingBO mappingRel=new RelationMappingBO();
	    String dateStr = DateUtils.formatDate("yyyyMMdd");
	    while ((lineBankInfo = br.readLine()) != null) {
	    	TaskInfoBO taskInfo=new TaskInfoBO();
	    	Log4jUtils.logDebug("lineBankInfo:"+lineBankInfo);
	    	String[] icbcButtjoinArr=lineBankInfo.split("\\^");
	    	/*获取影像批次号*/
			String businessNo=icbcButtjoinArr[0];
			/*业务识别号*/
			taskInfo.setBusinessNo(businessNo);
			String recordingDate=icbcButtjoinArr[1];
			/*获取客户姓名*/
			String customerName=icbcButtjoinArr[2];
			taskInfo.setCustomerName(customerName);
			/*得到相应的证件类型编码*/
			Log4jUtils.logDebug("对应的证件类型是："+icbcButtjoinArr[3]);
			//转换证件编码
			String customerCardType = bankButtjointDAO.queryIdcodeByUnion(icbcButtjoinArr[3],
					BusinessKey.BANK_BUTTJIONT_ICBC, BusinessKey.BANK_BUTTJIONT_CIITC);
			taskInfo.setCustomerCardType(Integer.parseInt(customerCardType));
			/*获取证件号码*/
			String customerCardNo=icbcButtjoinArr[4];
			taskInfo.setCustomerCardNo(customerCardNo);
			/*客户生日*/
    		String customerCardNoStr=taskInfo.getCustomerCardNo();
    		//String customerBirthdayNew=customerCardNoStr.substring(6, 14);
    		String customerBirthdayNew=DateUtils.parseStrToStr(customerCardNoStr.substring(6, 14), "yyyy-MM-dd");
    		taskInfo.setCustomerBirthday(customerBirthdayNew);
			/*获取产品代码*/
			String productCode=icbcButtjoinArr[5];
			taskInfo.setProductCode(productCode);
			/*获取地区号*/
			/*编码处理*/
			RelationMappingBO relationMappingBO;
			condMap.put("relationCode",icbcButtjoinArr[6]);
			condMap.put("relationType",BusinessKey.BANK_BUTTJIONT_ICBC);
			relationMappingBO=this.bankButtjointDAO.queryMappingTypeRel(condMap);
			if(relationMappingBO==null){
				RelationMappingBO relationMapping=new RelationMappingBO();
				relationMapping.setRelationCode(condMap.get("relationCode"));
				relationMapping.setRelationType(condMap.get("relationType"));
				relationMapping.setSysCode("91");
				this.bankButtjointDAO.addMappingTypeRel(relationMapping);
				relationMappingBO=this.bankButtjointDAO.queryMappingTypeRel(condMap);
			}
				Map<String, String> codeMap=new HashMap<String, String>();
				codeMap.put("sysCode",relationMappingBO.getSysCode());
				codeMap.put("relationType",BusinessKey.BANK_BUTTJIONT_CIITC);
				RelationMappingBO relationMapping=this.bankButtjointDAO.queryMappingTypeRel(codeMap);
				Log4jUtils.logDebug("中国保信关联机构编码为"+relationMapping.getRelationCode());
				taskInfo.setSubBankCode(relationMapping.getRelationCode());
				/*获取网点号*/
				String nodeBankCode=icbcButtjoinArr[7];
				taskInfo.setNodeBankCode(nodeBankCode);
				/*获取柜员号*/
				String counterId=icbcButtjoinArr[8];
				taskInfo.setCounterId(counterId);
				/*保险公司编号*/
	    		taskInfo.setSubInsurerCode(subInsurerCode);
	    		/*缴费方式*/
	    		taskInfo.setPaymentTerm(2);
	    		/*上传类型*/
				taskInfo.setUpdateTaskType(2);
				/*业务来源*/
				taskInfo.setTaskSource(1);
				/*工行编码*/
				/*编码处理*/
				taskInfo.setBankCode(icbcBankCode);
				/*保险公司总代码*/
				taskInfo.setInsurerCode(insurerCode);
				/*业务识别号类型*/
				taskInfo.setBusinessType(BusinessKey.CIITC_CONTNO_BUSINESSTYPE);
				list.add(taskInfo);
				CopyFileUtil.copyOneFile(ftpVideoPath+fileTxt.getName(),copyFile+dateStr+File.separator+fileTxt.getName());
				Log4jUtils.logDebug("**************备份文件结束*****************");
		} 
	    br.close();   
	    return list; 
	    }
	
	/************************对接中国邮储业务接口******************************************/
	@Override
	public void buttjointPSBCService(String bankType) {
		/*读取服务器zip*/
		String dateStr = DateUtils.formatDate("yyyyMMdd");
		String savePath=videoPath+File.separator+dateStr+File.separator;
		/*备份文件*/
		String copyPath=psbcCopyPath+File.separator+dateStr+File.separator;
		try
		{	
			File file = new File(bbcpPath+ File.separator) ;
			 if(file.isDirectory()){
			     File [] files= file.listFiles();
			     if(files!=null){
			     for(int i = 0 ; i<files.length ; i++){    
			    	if(files[i].getName().endsWith(".zip")){
			    		Log4jUtils.logDebug(files[i].getPath());
			    		String  tempbranchcode = null;
			    		unZipFiles(new File(files[i].getPath()),savePath,tempbranchcode);
			    		//进行文件的备份String videoFilePath=ftpVideoPath+File.separator+videoName;
			    		//CopyFileUtil.copyOneFile(videoFilePath,copyFile+dateStr+File.separator+videoName);
			    		tempbranchcode=null;//用完清空，防止占用内存
			    		CopyFileUtil.copyOneFile(files[i].getPath(),copyPath+files[i].getName());
			    		/*文件删除*/
			    		DelFileUtil.deleteOneFile(files[i].getPath());
			    		Log4jUtils.logDebug("=================删除文件结束============================");
			    	 }
			     } 
			 }
			   }
			
			
		} catch (IOException e1)
		{
			
			Log4jUtils.logError("buttjointPSBCService","@buttjointPSBCService-------buttjointPSBCService.excute(),错误："+e1.getMessage(),e1);
		}
		delete(new File(savePath));
	}
	
	 private  void delete(File zipFile) {
		 if(zipFile.exists()&&zipFile.isDirectory()){
			 File[] files=zipFile.listFiles();
			 if(files.length>0){
				 for (File file : files) {
					    if(file.getName().substring(file.getName().lastIndexOf(".")+1).equals("zip")||file.getName().substring(file.getName().lastIndexOf(".")+1).equals("txt")){
						   	if(file.exists()){
						   		file.delete();
						   		Log4jUtils.logDebug("成功删除"+file.getName());
							   	}else{
							   		Log4jUtils.logDebug("不存在此类文件!");
							   	}
					    }else{
					    	Log4jUtils.logDebug("邮储业务已对接完成，现在无对接业务!");
					    }
					} 
			 }else{
				 Log4jUtils.logDebug("没有执行的文件，此文件夹为空！");
			 } 
		 }else{
			 Log4jUtils.logDebug("现在无对接邮储的业务");
		 }
		 
	}
	@SuppressWarnings("rawtypes")
	public void unZipFiles(File zipFile, String descDir,String tempbranchcode) throws IOException
	{	
		String dateStr = DateUtils.formatDate("yyyyMMdd");
		String savePath=videoPath+File.separator+dateStr+File.separator;
		PSBCInfoDTO psbcInfo=new PSBCInfoDTO();
		ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK"));// 解决中文文件夹乱码
		String name = zip.getName().substring(zip.getName().lastIndexOf('\\') + 1, zip.getName().lastIndexOf('.'));
		//add by zyl 对zip文件名进行处理，目前就是保存对应的机构编码InsuranceFile_U_001_999_0026_20180525_001.zip start 
		String[] fristZipNames = name.split("\\_");
		if("BaseDataFile".equals(fristZipNames[0]) || "TranDataFile".equals(fristZipNames[0]) || "TranDataCompFile".equals(fristZipNames[0])
				|| "InsuranceFile".equals(fristZipNames[0]) || "InsuranceFileDtl".equals(fristZipNames[0])){
			tempbranchcode = fristZipNames[2];
			Log4jUtils.logDebug("获取的当前压缩文件的机构编码:"+tempbranchcode);
		}
		//add by zyl 20180621 保存对应的机构编码InsuranceFile_U_001_999_0026_20180525_001.zip end 
		for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements();)
		{	
			/*压缩文件的内容*/
			ZipEntry entry = (ZipEntry) entries.nextElement();
			String zipEntryName = entry.getName();
			InputStream in = zip.getInputStream(entry);
			String outPath = (descDir + "/" + zipEntryName).replaceAll("\\*", "/");
			/*判断路径是否存在,不存在则创建文件路径*/
			File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
			if (!file.exists())
			{
				file.mkdirs();
			}
			/*判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压*/
			if (new File(outPath).isDirectory())
			{
				continue;
			}
			/*输出文件路径信息*/
			FileOutputStream out = new FileOutputStream(outPath);
			byte[] buf1 = new byte[1024];
			int len;
			while ((len = in.read(buf1)) > 0)
			{
				out.write(buf1, 0, len);
			}
			in.close();
			out.close();
			if(entry.getName().endsWith(".zip")){
				unZipFiles(new File(savePath+zipEntryName), savePath,tempbranchcode);
			}else{
					String proposalNo;
					String viewName;
					String fileName=zipEntryName;
					if(fileName.endsWith(".txt")){
						proposalNo=fileName.substring(0, fileName.length()-4);
						Log4jUtils.logDebug("proposalNo:"+proposalNo);
						psbcInfo.setContno(proposalNo);
						String txtString = FileUtil.readToString(savePath+fileName);
						Log4jUtils.logDebug(fileName+"txt文件内容：:"+txtString);
						if(StringUtils.isNotBlank(txtString)){
							String[] opt = txtString.split("\\#\\+\\#");
							if(opt != null && opt.length == 3){
								psbcInfo.setFileDate(opt[2]);
							}
						}
					}else{
						viewName=zipEntryName;
						Log4jUtils.logDebug("viewName:"+viewName);
						psbcInfo.setVideoName(viewName);
					}
					
				}
		}
		if(psbcInfo.getContno()!=null&&psbcInfo.getVideoName()!=null){
			psbcInfo.setBranchCode(tempbranchcode);
			Log4jUtils.logDebug("获取的对象是:");
			Log4jUtils.logDebug(psbcInfo.toString());
			acceptInfo(psbcInfo);	
		}
		zip.close();
		Log4jUtils.logDebug("******************解压完毕********************");
		return;
	}

	/*处理邮储传入的信息参数*/
	private  void acceptInfo(PSBCInfoDTO psbcInfo) {
		Log4jUtils.logDebug("####新版本");
		TaskInfoBO taskInfo=new TaskInfoBO();
		Map<String, String>condMap=new HashMap<String, String>();
		String dateStr = DateUtils.formatDate("yyyyMMdd");
		String savePath=videoPath+File.separator+dateStr+File.separator;
		Log4jUtils.logDebug("--------");
		Log4jUtils.logDebug("---businessNo-----"+psbcInfo.getContno());
		/*截取字符串获得保单号*/
		String []proposalNos=psbcInfo.getContno().split("_");
		String proposalNo = proposalNos[0];
		/*业务识别号*/
		taskInfo.setBusinessNo(proposalNo);
		Log4jUtils.logDebug("contno:"+proposalNo);
//		/*根据保单号查询核心信息*/
//		List<PSBCInfoDTO> psbcInfoDTO=this.bankButtjointDAO.queryCoreInfo(proposalNo);
//		/*取第一条记录进行双录*/
//		PSBCInfoDTO info=psbcInfoDTO.get(0);
		Map<String, String> queryMap =new HashMap<String, String>();
		queryMap.put("prtno", proposalNo);
		CoreInfoDTO info = bankButtjointDAO.queryCoreLCbyBusinessNo(queryMap);
		if(info == null){
			info = bankButtjointDAO.queryCoreLBbyBusinessNo(queryMap);
		}
		//modify by zyl 20180614 添加对保单信息的空置判断，解决读取文件异常导致程序中断，执行完文件不能正常删除，进入死循环bug，
		if(info != null){
			Log4jUtils.logDebug("从核心获取数据为"+info.toString());
			Log4jUtils.logDebug("---videwName-----"+psbcInfo.getVideoName());
			//Log4jUtils.logDebug("第一条数据是："+info.toString());
			/*赋值处理*/
			/*判断视频的类型进行转码处理*/
			taskInfo.setCounterId(info.getBankOperator());
			taskInfo.setBankCode(psbcBnakCode);
			taskInfo.setNodeBankCode(info.getBankNode());
			/*保险公司编号*/
			//taskInfo.setSubInsurerCode(subInsurerCode);
			/*缴费方式转换*/
			/*1 -- 不定期交,
			0  -- 趸交,
			1  -- 月交
			3  -- 季交
			6  -- 半年交
			12 -- 年交*/
			int paymentTermInt=info.getPayIntv();
			if(paymentTermInt==0){
				paymentTermInt=BusinessKey.CIITC_WHOLE_PAY;
			}else if(paymentTermInt==1){
				paymentTermInt=BusinessKey.CIITC_IRREGULAR_PAY;
			}else{
				paymentTermInt=BusinessKey.CIITC_PERIOD_PAY;
			}
			taskInfo.setPaymentTerm(paymentTermInt);
			/*视频上传路径*/
			taskInfo.setVUrl(dateStr);
			/*上传类型*/
			taskInfo.setUpdateTaskType(2);
			/*业务来源*/
			taskInfo.setTaskSource(1);
			/*产品代码*/
			taskInfo.setProductCode(info.getRiskCode());
			/*客户姓名*/
			taskInfo.setCustomerName(info.getAppntName());
			/*保险公司总代码*/
			taskInfo.setInsurerCode(insurerCode);
			/*客户证件类型*/
			String idType=info.getAppntIdType();
			Log4jUtils.logDebug("idType:"+idType);
			//转换证件编码
			String customerCardType = bankButtjointDAO.queryIdcodeByUnion(idType,
					BusinessKey.BANK_BUTTJIONT_CODE, BusinessKey.BANK_BUTTJIONT_CIITC);
			taskInfo.setCustomerCardType(Integer.parseInt(customerCardType));
			/*分行编码进行转码*/
			/*获取邮储机构编码然后进行转码处理*/
//			RelationMappingBO relationMappingBO;
//			//modify by zyl 20180621  添加支行机构码  branchCode   机构对接-----邮政
//			String branchCode = psbcInfo.getBranchCode();
//			//condMap.put("relationCode",info.getBankBranch());
//			//Log4jUtils.logDebug("relationCode:"+info.getBankBranch());
//			condMap.put("relationCode",branchCode);
//			Log4jUtils.logDebug("relationCode:"+branchCode);
//			condMap.put("relationType",BusinessKey.BANK_BUTTJIONT_PSBC);
//			relationMappingBO=this.bankButtjointDAO.queryMappingTypeRel(condMap);
//			if(relationMappingBO==null){
//				RelationMappingBO relationMapping=new RelationMappingBO();
//				//relationMapping.setRelationCode(condMap.get("relationCode"));
//				relationMapping.setRelationCode(branchCode);
//				relationMapping.setRelationType(condMap.get("relationType"));
//				relationMapping.setSysCode("91");
//				this.bankButtjointDAO.addMappingTypeRel(relationMapping);
//				relationMappingBO=this.bankButtjointDAO.queryMappingTypeRel(condMap);
//			}
//			Log4jUtils.logDebug("关联内部机构编码为"+relationMappingBO.getSysCode());
//			Map<String, String> conMap=new HashMap<String, String>();
//			conMap.put("sysCode",relationMappingBO.getSysCode());
//			conMap.put("relationType",BusinessKey.BANK_BUTTJIONT_CIITC);
//			conMap.put("branchCode",branchCode);//add by zyl
//			RelationMappingBO relationMapping=this.bankButtjointDAO.queryMappingTypeRel(conMap);
//			Log4jUtils.logDebug("中国保信关联机构编码为"+relationMapping.getRelationCode());
//			//taskInfo.setSubBankCode(relationMapping.getRelationCode());
//			//Log4jUtils.logDebug("taskInfoBO.getSubBankCode():"+taskInfo.getSubBankCode());
//			taskInfo.setSubBankCode(branchCode == null?relationMapping.getRelationCode():branchCode );
			//根据查询核心的机构编码查询，对应的分公司信息
			String manageCom = info.getManageCom();
			if(StringUtils.isBlank(manageCom)){
				Log4jUtils.logDebug("从核心获取的机构编码manageCom为空");
			}else{
				DrsLdcomRelationBO queryDrsLdcomRel = bankButtjointDAO.queryDrsLdcomRel(manageCom);
				if(queryDrsLdcomRel != null){
					//分行编码
					taskInfo.setSubBankCode(queryDrsLdcomRel.getSubBankCode());
					//保险公司代码（省级分公司） 
					taskInfo.setSubInsurerCode(queryDrsLdcomRel.getSubInsurerCode());
				}
			}
			//1-保单号，2-投保单号，3-其他  目前邮储的都是投保单号，建行是保单号 20180628
			taskInfo.setBusinessType(2);
			//查询销售人员名称20180628
			Map<String, String> conMap=new HashMap<String, String>();
			conMap.put("bankCode",info.getBankCode());
			conMap.put("bankBranch",info.getBankBranch());
			conMap.put("bankNode",info.getBankNode());
			LaAgentBO laAgentBO = bankButtjointDAO.queryAgentName(conMap);
			if(laAgentBO != null){
				taskInfo.setCounterName(laAgentBO.getAgentName());
				taskInfo.setCounterPhone(laAgentBO.getAgentMobile());
			}
			taskInfo.setRecordTime(psbcInfo.getFileDate());//视频录制日期
//			Log4jUtils.logDebug("taskInfoBO.getSubBankCode():"+branchCode == null?relationMapping.getRelationCode():branchCode);
			/*客户证件号码*/
			taskInfo.setCustomerCardNo(info.getAppntIdNo());
			Date customerBirthday=info.getAppntBirthday();
			Log4jUtils.logDebug("customerBirthday:"+customerBirthday);
			String customerBirthdayStr=DateUtils.formatDate(customerBirthday,"yyyy-MM-dd");
			Log4jUtils.logDebug("customerBirthdayStr:"+customerBirthdayStr);
			taskInfo.setCustomerBirthday(customerBirthdayStr);
			/*业务识别号类型*/
			taskInfo.setBusinessType(BusinessKey.CIITC_PROPOSALNO_BUSINESSTYPE);
			/*获取完整的视频路径*/
			String videoLocalPath=videoPath+File.separator+dateStr+File.separator+psbcInfo.getVideoName().substring(0,psbcInfo.getVideoName().length()-4);
			String videoAllPath=videoPath+File.separator+dateStr+File.separator+psbcInfo.getVideoName();
			File videoFile=null;
			if(!psbcInfo.getVideoName().endsWith(".mp4")){
				VideoConvertUtil.processFLV(videoAllPath, videoLocalPath, ffmpegPath);
				String videoName=psbcInfo.getVideoName().substring(0,psbcInfo.getVideoName().length()-4)+".flv";
				taskInfo.setVideoName(videoName);
				taskInfo.setVideoType(videoName.substring(videoName.length()-3, videoName.length()));
				/*获取视频文件的长度*/
				String videoNewPath=videoPath+File.separator+dateStr+File.separator+videoName;
				videoFile=new File(videoNewPath);
				taskInfo.setFileLength(videoFile.length());
				Log4jUtils.logDebug("获取到的视频文件长度是："+taskInfo.getFileLength());
				/*获取视频文件的时长*/
				taskInfo.setFileTime(VideoFileUtils.getVideoFileTime(videoNewPath));
				Log4jUtils.logDebug("获取到视频文件时长为:"+VideoFileUtils.getVideoFileTime(videoNewPath));
				DelFileUtil.deleteOneFile(videoAllPath);
			}else{
				taskInfo.setVideoName(psbcInfo.getVideoName());
				taskInfo.setVideoType(psbcInfo.getVideoName().substring(psbcInfo.getVideoName().length()-3, psbcInfo.getVideoName().length()));
				/*获取视频文件的长度*/
				videoFile=new File(videoAllPath);
				taskInfo.setFileLength(videoFile.length());
				Log4jUtils.logDebug("获取到的视频文件长度是："+taskInfo.getFileLength());
				/*获取视频文件的时长*/
				taskInfo.setFileTime(VideoFileUtils.getVideoFileTime(videoAllPath));
				Log4jUtils.logDebug("获取到视频文件时长为:"+VideoFileUtils.getVideoFileTime(videoAllPath));
				
			}
			Log4jUtils.logDebug("task:"+taskInfo.toString());
			int createFlag=this.taskInfoDAO.addTaskInfo(taskInfo);
			if(createFlag<1){
				Log4jUtils.logDebug("上传失败！！！");
			}else{
				DrsAsynchTaskBO drsAsynchTask = new DrsAsynchTaskBO();
				drsAsynchTask.setBusinessNo(taskInfo.getBusinessNo());
				drsAsynchTask.setBusinessSerialNo(taskInfo.getBusinessSerialNo());
				drsAsynchTask.setTaskType(BusinessKey.ASYNCH_TYPE_UB);
				drsAsynchTask.setStatus(BusinessKey.ASYNC_TASK_STATUS_WAIT);
				drsAsynchTaskDAO.addDrsAsynchTask(drsAsynchTask);
			}
		}else{
			Log4jUtils.logDebug("核心无对应的保单信息，保单号prtno："+proposalNo);
		}
	}

	
	
	
	
	
}